/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.configuration;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.merak.core.configuration.plugin.PluginSet;
import org.merak.core.configuration.web.mvc.WebMVC;
import org.merak.core.model.parameter.Property;

public class Configuration {

	//~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private String                name              = null;
	private String                description       = null;
	private WebMVC                webMVC            = new WebMVC();
	private Map<String,PluginSet> pluginSets        = new HashMap<String,PluginSet>();
	private Map<String,Property>  propertySet       = new HashMap<String,Property>();
	private List<Property>        systemPropertySet = new ArrayList<Property>();

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	public String getName() {
		return this.name;
	}
	//****************************************************************************
	public void setName(String name) {
		this.name = name;
	}
	//****************************************************************************
	public String getDescription() {
		return this.description;
	}
	//****************************************************************************
	public void setDescription(String description) {
		this.description = description;
	}
	//****************************************************************************
	public WebMVC getWebMVC() {
		return this.webMVC;
	}
	//****************************************************************************
	public void setWebMVC(WebMVC webMVC) {
		this.webMVC = webMVC;
	}
	//****************************************************************************
	public void addProperty(Property property) {
		this.propertySet.put(property.getName(),property);
	}
	//****************************************************************************
	public Property getProperty(String name) {
		return this.propertySet.get(name);
	}
	//****************************************************************************
	public void addSystemProperty(Property property) {
		this.systemPropertySet.add(property);
	}
	//****************************************************************************
	public Collection<Property> getProperties() {
		return this.propertySet.values();
	}
	//****************************************************************************
	public Collection<Property> getSystemProperties() {
		return this.systemPropertySet;
	}
	//****************************************************************************
	public PluginSet getServiceSet(String spiPackage) {
		return this.pluginSets.get(spiPackage);
	}
	//****************************************************************************
	public void addServiceSet(PluginSet plugins) {
		this.pluginSets.put(plugins.getSpiPackage(),plugins);
	}
	//****************************************************************************
	@Override
	public String toString() {

		String s = this.name + ", " + this.description + "\n";
		for (Property p : this.propertySet.values()) {
			s += p;
		}
		s += "\n";
		for (Property p : this.systemPropertySet) {
			s += p;
		}
		s += "\n";
		for (PluginSet p : this.pluginSets.values()) {
			s += p;
		}
		return s;

	}
	//****************************************************************************

}
